<include file="headerone"/>
	<div class="head clearfix">
		<a href="javascript:history.back(-1)" class="iconfont icon-zuo"></a>
		<span class="head-name">确认支付</span>
	</div>
	<div class="lists">会议名称：{BEESCRM:$data.title}</div>
	<div class="lists">参会费用：¥{BEESCRM:$cost}</div>
	<div class="lists">收款方：{BEESCRM:$data.sponsor}</div>
	<div class="btn-box">
		<a href="#" class="btn bg-green" id="enroll_pay" data-id="{BEESCRM:$order_id}" data-cost="{BEESCRM:$cost}">立即支付</a>
	</div>
<!--<include file="footer"/>-->

<script>
	/*$(document).ready(function(){
		// 验证倒计时
		var hc = $('#enroll_pay').hasClass('settim');
		if(!hc){
    		_interval = setInterval("showTime()", 1000);
    	}
	})
	var i = 2;
	function showTime(){
			if(i >= 0){					
				str = "立即支付("+i+")";
				$('#enroll_pay').html(str);
				i--;
			}

			if(i < 0){					
				$('#enroll_pay').addClass('settim');
				str = "立即支付";
				$('#enroll_pay').html(str);
				$("#enroll_pay").addClass('bg-green');
				$('#enroll_pay').removeClass('bg-grey');
				clearInterval(_interval);
			}
	}*/
	$(document).ready(function(){
	//提交订单
		$('#enroll_pay').click(function(){
		    if ($(this).hasClass('bg-green')) {
		        $(this).removeClass('bg-green');
		        $(this).addClass('bg-grey');
		        $(this).text('支付中');
		        var cost = $(this).data('cost');
		        var order_id = $(this).data('id');
		
		        $.ajax({
		            url: "/meetingwyd/meetingEnroll/wxpay/",
		            data: {'order_id': order_id, 'cost': cost},
		            dataType: 'json',
					'type': 'POST',
					'async': false,
					beforeSend: function(){	 
						 $('#show_loading').show();
					},
					success: function(data) {
						$('#show_loading').hide();
						if (data.status == 'S') {
							var wxpay = $.parseJSON(data.wxpay);
							var enroll_id = data.enroll_id;
							pay(wxpay,enroll_id);
						}else{
							$.alert('error',data.message);
							return false;
						}
					}
				});
			}
		});
		
			//微支付
			function pay(wxpay,id){
		
				if (typeof WeixinJSBridge == "undefined"){
					if( document.addEventListener ){
						document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
					}else if (document.attachEvent){
						document.attachEvent('WeixinJSBridgeReady', jsApiCall);
						document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
					}
				}else{
					WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						wxpay,
						function(res){
							if(res.err_msg == "get_brand_wcpay_request:ok"){
								$('#enroll_pay').text('已支付');
                                location.href = '/meetingwyd/meetingEnroll/meetingDetail/enroll_id/'+id;
							}else if(res.err_msg == "get_brand_wcpay_request:cancel"){
								//$.alert('error','付款已取消');
								$('#enroll_pay').removeClass('bg-grey');
		        				$('#enroll_pay').addClass('bg-green');
		        				$('#enroll_pay').text('立即支付');
								return false;
							}else{
								alert(res.err_msg);
								$.alert('error','调用微支付失败');
								return false;
							}
						}
					);
				}
			}
		
	/*		function paySuccess(order_id){
				//var json = {};
				var applyId = $("#applyId").val();
				var order_id = $('.btn').data('order_id');
				$.ajax({
					'url':"/Base/BusBooking/paysuccess/apply_id/"+applyId+"/order_id/"+order_id,
					'data': {},
					'dataType': 'json',
					'type': 'POST',
					success: function (data) {
						if (data.status == 'S') {
							location.href = data.url;
						} else {
							fm.alert(data.message);
							return false;
						}
					}
				})
			}*/
		
			//页面刷新
			function reload() {
				setTimeout('location.reload()', 2000);
			}

	});
</script>